package com.Dubbo.RWSeparate.provider.read.mainLoader;

import java.util.Properties;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DemoDubboTest {

	public static void main(String[] args) throws Exception {
		
		String druid_dataSource_url = "jdbc:mysql://127.0.0.1:3306/mybatistest";
		
		// Create a Parser  
		CommandLineParser parser = new BasicParser( );
		Options options = new Options( );  
		options.addOption("u", "druid_dataSource_url", true, "druid_dataSource_url");
		
		options.addOption("h", "help", false, "parameter information"); 
		
		CommandLine commandLine = parser.parse( options, args );
		
		if( commandLine.hasOption('h') ) {
			System.out.println("-u: druid_dataSource_url");
			return;
		}
		
		if( commandLine.hasOption('u') ) {
			druid_dataSource_url = commandLine.getOptionValue('u');  
		}  
		System.out.println("数据库连接池url："+ druid_dataSource_url);
		
		//在 ClassPathXmlApplicationContext 启动之前，自定义配置部分参数，用来设定启动过程中的部分参数设置
		PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
		Properties properties = new Properties();
		properties.setProperty("druid.dataSource.url", druid_dataSource_url);
		
		configurer.setProperties(properties);
		
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.addBeanFactoryPostProcessor(configurer);
		context.setConfigLocations(new String[] { "META-INF/spring/DubboSpringAll.xml" });
		context.refresh();
		
		context.start();
		System.in.read(); // 按任意键退出
		
	}
	
	
}
